/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ua.i.kotionokyurievna.jewelry.logic;

import java.util.List;
import ua.i.kotionokyurievna.jewelry.domain.productcatalog.ProductCatalog;

/**
 *
 * @author Kateryna_Reznik
 */
public class Catalogue {
    private List<ProductCatalog> itemsList;
    
    public Catalogue(){
        
    }

    public Catalogue(List<ProductCatalog> itemsList) {
        this.itemsList = itemsList;
    }
    
    public Catalogue ( Catalogue catalogue ){
        if ( catalogue != null ){
            this.itemsList = catalogue.itemsList;
        }
    }
    
    public boolean addProductItem(ProductCatalog productCatalog){
        if ( !find(productCatalog )){
            itemsList.add(productCatalog);
            return true;
        }
        return false;
    }
    
    public boolean find(ProductCatalog productCatalog){
        return itemsList.contains(productCatalog);
    }
    
    public boolean removeProductItem(ProductCatalog productCatalog){
        if ( find(productCatalog )){
            itemsList.remove(productCatalog);
            return true;
        }
        return false;
    }
    
    public boolean changeProductItem( ProductCatalog productCatalogOld, 
            ProductCatalog productCatalogNew ){
        if ( find( productCatalogOld )){
            int itemNumber = itemsList.indexOf(productCatalogOld);
            itemsList.add(itemNumber, productCatalogNew);
            itemsList.remove(itemNumber + 1);
            return true;
        }
        return false;
    }
    
}
